﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH.DB_Map.ywxt
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    using DB_NH.DB_Model.ywxt;

    public class t_project_Map : ClassMapping<t_project>
    {
        public t_project_Map()
        {
            //映射ID
            Id(x => x.proj_id, map => map.Length(40));

            Property(x => x.is_valid);
            Property(x => x.create_date);

            Property(x => x.is_leaf);
            Property(x => x.proj_level);
            Property(x => x.proj_code, map => map.Length(20));
            Property(x => x.proj_jg, map => map.Length(200));
            Property(x => x.proj_name, map => map.Length(200));
            Property(x => x.pre_proj_id, map => map.Length(40));
            Property(x => x.proj_order_flag, map => map.Length(40));
            Property(x => x.proj_wtsj);
            Property(x => x.proj_xmly);

            Property(x => x.ProjectBDW, map =>
            {
                map.Column("proj_bdwmc");
            });
            Property(x => x.ProjectYear, map =>
            {
                map.Column("proj_year");
            });
            Property(x => x.ProjectRemark, map =>
            {
                map.Column("proj_remark");
                map.Length(400000);
            });
            Property(x => x.ProjectNBFL, map => {
                map.Column("proj_nbfl");
                map.Length(40);
            });
            Property(x => x.ProjectWBBH, map =>
            {
                map.Column("proj_wbbh");
                map.Length(40);
            });
            Property(x => x.ProjectZJLY, map =>
            {
                map.Column("proj_zjly_id");
                map.Length(40);
            });
            Property(x => x.ProjectXMXZ, map =>
            {
                map.Column("proj_xmxz_id");
                map.Length(40);
            });
            Property(x => x.ProjectZBNR, map =>
            {
                map.Column("proj_zbbd_id");
                map.Length(40);
            });
            Property(x => x.ProjectZBFS, map =>
            {
                map.Column("proj_zbfs_id");
                map.Length(40);
            });
            Property(x => x.proj_wtsbh, map => map.Length(40));
            Property(x => x.proj_zbtzsbh, map => map.Length(40));
            Property(x => x.proj_zbsj);

            Property(x => x.proj_status_code, map => map.Length(40));
            Property(x => x.proj_status);

            //收费方式
            Property(x => x.proj_sffs, map => map.Length(40));
            Property(x => x.proj_sffsz);

            //保证金收取方式
            Property(x => x.proj_bzj_fs, map => map.Length(40));
            Property(x => x.proj_bzj);

            //总投资
            Property(x => x.proj_ztz);
            //总投资美元
            Property(x => x.proj_ztz_my);

            //项目所属部门
            ManyToOne(x => x.department, map =>
            {
                map.Column("proj_create_dept_id");
                map.NotNullable(false);
            });

            //项目创建人
            ManyToOne(x => x.Creator, map =>
            {
                map.Column("proj_create_user_id");
                map.NotNullable(false);
            });

            //项目业主
            ManyToOne(x => x.Owner, map =>
            {
                map.Column("proj_owner_ent_id");
                map.NotNullable(false);
            });

            //关联盖章详细记录
            Bag(x => x.ywgzs, map => map.Key(km => km.Column(DB_Model.YWGZ.wf_ywgz.Columns.gz_proj_id)), act => act.OneToMany());

            //关联专家抽取记录
            Bag(x => x.proj_extracts, map =>
            {
            }, act => act.ManyToMany());

            //关联专家抽取记录
            Bag(x => x.proj_extract_baks, map =>
            {
            }, act => act.ManyToMany());

            //关联项目费用
            Bag(x => x.proj_fys, map => map.Key(km => km.Column(fy_detail.Columns.fy_proj_id)), act => act.OneToMany());

            //关联项目的供应商
            Bag(x => x.proj_Enterprises, map =>
            {
                map.Key(keyMapper => keyMapper.Column("proj_id"));
            }, rel => rel.OneToMany());

            //项目包含的奖金支取申请
            Bag(x => x.ProjectJJSQs, map =>
            {
                map.Table("ref_Project_to_JJSQs");
                map.Key(keyMapper => keyMapper.Column("ProjId"));
            }, act => act.ManyToMany(m => m.Column("JJSQId")));

            //项目对应的时间安排
            Bag(x => x.RefProjectAndPlans, map =>
            {
                map.Table("r_project_plan");
                map.Key(keyMapper => keyMapper.Column("proj_id"));
            }, act => act.OneToMany());

            //对应奖金表申请关系（多对多）
            Bag(x => x.ProjectJJBs, map =>
            {
                map.Table("ref_Project_JJBs");
                map.Key(keyMapper => keyMapper.Column("ProjId"));
            }, act => act.ManyToMany(m => m.Column("JJBId")));

            //项目的签到记录
            Bag(x => x.ProjectQDs, map =>
            {
                map.Table("t_project_open_qdb");
                map.Key(keyMapper => keyMapper.Column("proj_id"));
            }, act => act.OneToMany());

            //项目的开标记录表定义
            Bag(x => x.ProjectOpenRows, map =>
            {
                map.Key(keyMapper => keyMapper.Column("ProjectId"));
            }, act => act.OneToMany());

            Table("t_project");

            //不进行创建
            //SchemaAction(NHibernate.Mapping.ByCode.SchemaAction.None);
        }
    }
}
